package cn.edu.jxyy.mybatistest.test;

import cn.edu.jxyy.mybatistest.Utils.MyBatisUtils;
import cn.edu.jxyy.mybatistest.mapper.StudentMapper;
import cn.edu.jxyy.mybatistest.pojo.Student;
import org.apache.ibatis.session.SqlSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class part16_2 {
    public static void findByArrayTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Integer[] roleIds = {2, 3};
        StudentMapper studentMapper =
                sqlSession.getMapper(StudentMapper.class);
        List<Student> students = studentMapper.findByArray(roleIds);
        for (Student student : students) {
            System.out.println(student);
        }
        sqlSession.close();
    }

    public static void findByListTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        List<Integer> ids = new ArrayList<Integer>();
        ids.add(1);
        ids.add(2);
        StudentMapper studentMapper =
                sqlSession.getMapper(StudentMapper.class);
        List<Student> students = studentMapper.findByList(ids);
        for (Student student : students) {
            System.out.println(student);
        }
        sqlSession.close();
    }

    public static void findByMapTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        List<Integer> ids = new ArrayList<Integer>();
        ids.add(1);
        ids.add(2);
        ids.add(3);
        Map<String, Object> conditionMap = new HashMap<String, Object>();
        conditionMap.put("id", ids);
        conditionMap.put("age", "25");
        StudentMapper studentMapper =
                sqlSession.getMapper(StudentMapper.class);
        List<Student> students =studentMapper.findByMap(conditionMap);
        for (Student student : students) {
            System.out.println(student);
        }
        sqlSession.close();
    }

    public static void main(String[] args){
        findByArrayTest();
        findByListTest();
        findByMapTest();
    }

}
